---
import PostLayout from "@layouts/PostLayout.astro";

import MarkdownContainer from "@components/MarkdownContainer.astro"

import { getCollection } from 'astro:content'
import { selectNearPosts } from "@utils/astroUtil";

export async function getStaticPaths() {
    const posts = await getCollection('posts');
    return posts.map(post => ({
        params: { slug: post.slug }, props: { post },
    }));
}

const { post } = Astro.props
const { Content, headings } = (await post.render())
const nearPost = await selectNearPosts(post.id)
---

<PostLayout 
    frontmatter={ post.data }
    nearPosts={ nearPost }
    headings={ headings }>
    
    <MarkdownContainer isDraft={ post.data.draft }>
        <Content />
    </MarkdownContainer>

</PostLayout>